package client;

import java.io.File;
import java.util.Properties;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.readaloud.hibernate.user.Author;
import com.readaloud.hibernate.user.Books;
import com.readaloud.hibernate.user.Books_old;
import com.readaloud.hibernate.user.Comment;
import com.readaloud.hibernate.user.Reader;
import com.readaloud.indexing.KeyWord;
import com.readaloud.inverted.Registry;



public class Client {

	/**
	 * @param args
	 */
	public static void main(String[] args) {/*
		// TODO Auto-generated method stubj
		
		Reader reader = new Reader();
		reader.setUserName("ReaderUserName");
		reader.setPassword("ReaderPassord");
		reader.setReaderName("ReaderName");
		
		Author author = new Author();
		author.setUserName("AuthorUserName");
		author.setPassword("AuthorPassword");
		author.setAuthorName("AuthorName");
		
		Books_old book = new Books_old();
		book.setBookName("book1");
		
		//book.parsebook("C://greenninja//11.txt");
		book.parsebook("C://CMPE226//books//11.txt");
		book.setBookAuthor(book.getBookAuthor());
		book.setTitle(book.getTitle());
		book.setReleaseDate(book.getReleaseDate());
		book.setLanguage(book.getLanguage());
		
		Comment comment = new Comment();
		comment.setCommentDesc("comment1");
		
		Comment comment1 = new Comment();
		comment1.setCommentDesc("comment2");
		
		book.getComment().add(comment);
		book.getComment().add(comment1);
		
		comment.setBooks(book);
		comment1.setBooks(book);
		
		
		//author book many to many
				Books_old book2 = new Books_old();
				book2.setBookName("book2");
				
				Author author2 = new Author();
				author2.setUserName("author2UserName");
				author2.setPassword("password2");
				author2.setAuthorName("AuthorName2");
				
				author.getBooksList().add(book);
				author.getBooksList().add(book2);
				
				author2.getBooksList().add(book2);
				author2.getBooksList().add(book);
				
				book.getAuthorList().add(author);
				book.getAuthorList().add(author2);
				book2.getAuthorList().add(author);
				book2.getAuthorList().add(author2);
				
				//============
				// books readers many to many
				
				Reader reader2 = new Reader();
				reader2.setUserName("userNameReader2");
				reader2.setPassword("password2Reader");
				reader2.setReaderName("Reader2Name");
				
				book.getReaderList().add(reader);
				book.getReaderList().add(reader2);
				
				reader.getBookList().add(book);
				reader.getBookList().add(book2);
				
				//====
				//reader to add comments one to many
				
				reader.getReaderCommentList().add(comment);
				reader.getReaderCommentList().add(comment1);
				
				
				Document doc = new Document(file);
				
				KeyWord key = new KeyWord("aasdasd", 1);
				doc.setDescription("desc");
				doc.getKeywords().put("aaa",key);
				
		SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
		
		Session session = sessionFactory.openSession();
		
		session.beginTransaction();
		
		//session.save(doc);
		
		
		//user type saving
		session.persist(reader);
		session.save(author);
		
		//book and comment saving
		session.persist(book); //CascadeType.ALL so persist and remove comment, it will auto persist coment
		session.save(comment);
		session.save(comment1);
		session.save(reader2);
		session.save(author2);
		session.persist(book2);
		session.save(author);
		session.save(reader);
		
		//session.getTransaction().commit();
		//session.close();
		
		Properties conf = new Properties();
		conf.setProperty("stop.words.file", "resources/stopwords-long.txt");
		conf.setProperty("data.storage", "data");
		
		File file = new File("C://CMPE226//books//11.txt");

		if (file.isFile())
			System.out.println("file");
		else {
			System.out.println("no file");
		}
		
		Registry reg = new Registry(conf);
		
		reg.register(file,session);
		
		session.getTransaction().commit();
		session.close();
		
		System.out.println("Done......");

	*/}

}
